Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataOffload: Field offload of driver regions #457

Merged
merged 15 commits into from
Jan 13, 2025

Conversation

mlange05
Copy link
Collaborator

@mlange05 mlange05 commented Dec 5, 2024

This PR refactors the current Field-API offload transformation and its utilities and adds two previously missing features:

  • The ability to detect aliased array pointer usage, so CALL F(obj%a(:, 1), obj%a(:, 2)) only declares and offloads obj_a once.
  • The ability to run FieldOffloadTransformation over compute regions in drivers without kernel calls

Moreover, it turns I've started moving things around a little and ended up putting most of the heavy lifting in the FieldPointerMap utility. To avoid future cyclic import and other issues, I've then moved this out to a pure helper sub-module loki.transformations.field_api and renamed the using transformations data_offload.field_offload and parallel.field_views.

In refactoring the existing transformation and utilities to achieve the above, I moved quite a few things around - sorry for the large diff. I'd be happy to split this up, if this will aid the review process.

In a little more detail, the other changes in this PR are:

  • Refactoring Field API offload tests to use a common fixture for state_type, where appropriate
  • Filtering duplicates at alls stages via dict.fromkeys instead of set, as this retains ordering and thus ensures reproducible orders of variables/utility calls at all stages
  • The FieldPointerMap not converts from field view array symbols to general data pointers (with block dimension) on-the-fly. This allows the data pointers to be given as a mere property on the pointer map object.
  • Similarly the FieldPointerMap now provides the lists of boilerplate calls for host-to-device copies and host-sync calls as properties and derives them from the three internally stored argument/array symbol lists.
  • Apply symbol substitution over all array symbols that match the pointer/array symbols stored in the field pointer map over an entire region, not just calls
  • Derive the array symbols for which to generate Field API offload semantics via dataflow analysis, so that we can run this over any marked pragma region

@mlange05 mlange05 requested review from wertysas and awnawab December 5, 2024 19:37
Copy link

github-actions bot commented Dec 5, 2024

Documentation for this branch can be viewed at https://sites.ecmwf.int/docs/loki/457/index.html

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 99.07834% with 2 lines in your changes missing coverage. Please review.

Project coverage is 93.29%. Comparing base (ad1e2bc) to head (cede76b).
Report is 59 commits behind head on main.

Files with missing lines Patch % Lines
loki/transformations/data_offload/field_offload.py 98.66% 1 Missing ⚠️
loki/transformations/field_api.py 98.59% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #457   +/-   ##
=======================================
  Coverage   93.29%   93.29%           
=======================================
  Files         221      222    +1     
  Lines       41360    41387   +27     
=======================================
+ Hits        38587    38613   +26     
- Misses       2773     2774    +1     
Flag Coverage Δ
lint_rules 96.39% <ø> (ø)
loki 93.25% <99.07%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mlange05 mlange05 marked this pull request as ready for review December 6, 2024 03:25
Copy link
Contributor

@wertysas wertysas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's very nice to get these extensions of the field offload capabilities. It makes a lot of sense to separate the field utilities and offload transformations like this and I think it's very nice to have the offload map tracking the offload variables like this👍.

loki/transformations/field_api.py Outdated Show resolved Hide resolved
loki/transformations/field_api.py Show resolved Hide resolved
loki/transformations/field_api.py Show resolved Hide resolved
loki/transformations/data_offload/field_offload.py Outdated Show resolved Hide resolved
loki/transformations/field_api.py Show resolved Hide resolved
loki/transformations/field_api.py Outdated Show resolved Hide resolved
loki/transformations/field_api.py Outdated Show resolved Hide resolved
loki/transformations/field_api.py Outdated Show resolved Hide resolved
@mlange05
Copy link
Collaborator Author

mlange05 commented Jan 6, 2025

Hi @wertysas , thanks for the review. I believe I've addressed all comments now (top two commits). Please have another look and let me know if you're happy. I'll then rebase on latest main for final integration.

@mlange05 mlange05 force-pushed the naml-field-offload-regions branch from 4acdc97 to 82431ab Compare January 6, 2025 14:30
Copy link
Contributor

@wertysas wertysas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! I'm very happy with this refactoring of the offload transformations and the new additions.

Sets are unordered, so using them to filter creates an arbitrary
ordering, which in turn yields an unpredictable order of declarations.
This allows us to re-use the key pieces without being hooked into
the `!$loki data` regions semantics.
Instead of subbing just on calls, we apply the remapping over the
whole routine body.
Without tying the transformation to calls, explicit no-target skipping
becomes virtually impossible; hence removing the test for it.
@mlange05 mlange05 force-pushed the naml-field-offload-regions branch from 82431ab to cede76b Compare January 7, 2025 09:36
@mlange05
Copy link
Collaborator Author

Ok, initial comments on this have been addressed and I've rebased this fairly recently. @awnawab Did you want to take a quick look over this before we merge it?

@awnawab
Copy link
Contributor

awnawab commented Jan 13, 2025

Hi @mlange05. I'm happy to take a look at this, but I'll only be able to get to this closer to the end of play today. If you'd like it merged sooner than that then please go ahead.

Copy link
Contributor

@awnawab awnawab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the updated structure of the F-API utilities, looks great, many thanks 😄

@reuterbal reuterbal merged commit c054b46 into main Jan 13, 2025
13 checks passed
@reuterbal reuterbal deleted the naml-field-offload-regions branch January 13, 2025 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants